﻿Imports BUS
Imports DTO
Public Class ucKhuVuc
    Dim kv As New KhuVucDTO

    Private Sub barbtnThemKhoHang_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles barbtnThemKhoHang.ItemClick
        Dim frm As New frmThemKhuVuc()
        frm.ShowDialog()
    End Sub

    Public Sub loadDSKhuVuc()
        GridControl1.DataSource = KhuVucBUS.LayDSKhuVuc()
    End Sub

    Public Sub ucKhuVuc_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        barbtnSuaChuaKV.Enabled = False
        barbtnXoaKV.Enabled = False
        barbtnXuatKV.Enabled = False

        loadDSKhuVuc()

    End Sub

    Private Sub barbtnNapLaiKhoHang_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles barbtnNapLaiKhoHang.ItemClick
        loadDSKhuVuc()
    End Sub


    Private Sub barbtnDongKV_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles barbtnDongKV.ItemClick

    End Sub

    Private Sub gvLoadKV_RowClick(sender As Object, e As DevExpress.XtraGrid.Views.Grid.RowClickEventArgs) Handles gvLoadKV.RowClick
        If e.RowHandle >= 0 Then
            barbtnSuaChuaKV.Enabled = True
            barbtnXoaKV.Enabled = True
            kv.MaKhuVuc = gvLoadKV.GetRowCellValue(e.RowHandle, gvcMaKV).ToString()
            kv.TenKhuVuc = gvLoadKV.GetRowCellValue(e.RowHandle, gvcTenKV).ToString()
            kv.GhiChu = gvLoadKV.GetRowCellValue(e.RowHandle, gvcGhiChuKV).ToString()
            kv.MaTrangThai = Convert.ToInt32(gvLoadKV.GetRowCellValue(e.RowHandle, gvcConQuanLy))
        End If

    End Sub

    Private Sub barbtnSuaChuaKV_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles barbtnSuaChuaKV.ItemClick
        Dim frm As New frmThemKhuVuc()
        frm.maKV = kv.MaKhuVuc
        frm.TenKV = kv.TenKhuVuc
        frm.GhiChu = kv.GhiChu
        frm.MaTT = kv.MaTrangThai
        frm.Text = "Sửa Chữa Khu Vực"
        frm.kt = 1
        frm.ShowDialog()
    End Sub

    Private Sub barbtnXoaKV_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles barbtnXoaKV.ItemClick
        Try
            If KhuVucBUS.XoaKhuVuc(kv) Then
                'Dim frm As New frmMain
                'HeThongBUS.themNhatKy(frm.maND, "Danh Mục", "Xóa", "Khu vực")
                DevExpress.XtraEditors.XtraMessageBox.Show("Đã xóa thành công", "Thông Tin", MessageBoxButtons.OK, MessageBoxIcon.Information)
                loadDSKhuVuc()
            End If
        Catch ex As Exception
            DevExpress.XtraEditors.XtraMessageBox.Show("Không thể xóa vì khu vực này đang được sử dụng", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error)
            KhuVucBUS.DongKetNoi.Close()
        End Try

    End Sub

    Private Sub gvLoadKV_CustomDrawRowIndicator(sender As Object, e As DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs) Handles gvLoadKV.CustomDrawRowIndicator
        If e.RowHandle >= 0 Then
            If e.Info.IsRowIndicator Then
                e.Info.DisplayText = (e.RowHandle + 1).ToString()
            End If
        End If
    End Sub
End Class
